﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Big_Data.Excel;
using Microsoft.Office.Interop.Excel;
using Big_Data.Data_Base_Excel;
using System.Configuration;

namespace Big_Data.Excel
{
    class Graphic : Excel_File
    {
        public Range rngStart;
        public Range rngEnd;
        public Chart chart;

        public static int row_pays = Convert.ToInt32(ConfigurationManager.AppSettings["row_value_pays_graph"]);
        public static int col_date = Convert.ToInt32(ConfigurationManager.AppSettings["col_value_date_graph"]);
        public static int col_pays_value = Convert.ToInt32(ConfigurationManager.AppSettings["col_value_pays_graph"]);
        public int col_pays=col_pays_value;
        public int col_val = 0;
        public int nb_insert_date = 0;
        public int rows_val = 0;
        public int rows_end = 0;

        public void createGraph(string title,object type)
        {
            Console.WriteLine(type.ToString());
            ChartObjects chartObjects = workSheet.ChartObjects();
            ChartObject chartObject = chartObjects.Add(60,10,300,300);
            chart = chartObject.Chart;
            Range chartRange;
            
            chartRange = workSheet.get_Range(rngStart,rngEnd);
            chart.SetSourceData(chartRange, Type.Missing);
            chart.ChartType = (XlChartType)type;
            chart.ChartWizard(Source: chartRange, Title: title);
            chart.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
            workBook.Save();

            col_pays = col_pays_value;
            rows_end = rows_val = nb_insert_date = col_val = 0;
        }

        public void AddValueSheet(string pays,string name, Dictionary<string, string> dictAnnéeValeurs)
        {
            workSheet = workBook.ActiveSheet;
            rngStart = (Range)workSheet.Cells[row_pays, col_date];
            //foreach (var pays in lstpays)
            //{
                workSheet.Cells[row_pays, col_pays] = pays + "("+name+")";
                col_val = col_pays;
                rows_val = row_pays;
                col_pays++;
            //}
            foreach (var item in dictAnnéeValeurs)
            {
                rows_val++;
                if (nb_insert_date<dictAnnéeValeurs.Keys.Count)
                {
                    workSheet.Cells[rows_val, col_date] = item.Key;
                    nb_insert_date++;
                    rows_end = rows_val;
                }
             
                workSheet.Cells[rows_val,col_val] = double.Parse(item.Value);
            }
            rngEnd = (Range)workSheet.Cells[rows_end, col_val];
        }
    }
}
